package com.blue.base.local.test.es;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liulei44
 * @date 2022/5/8 10:42 PM
 */
@Slf4j
@Configuration
@ConditionalOnProperty(value = "es.config.host")
public class ESConfig {

    @Value("${es.config.host}")
    private String host;
    @Value("${es.config.port}")
    private Integer port;

    @Bean
    public RestHighLevelClient restHighLevelClient() {
        log.info("==========初始化ES配置==========");
        return new RestHighLevelClient(RestClient.builder(new HttpHost(host, port, "http"))
                .setRequestConfigCallback(builder -> builder.setConnectTimeout(30000)
                        .setConnectionRequestTimeout(30000)));
    }
}
